package com.sy.simpleegg.room.repository

import com.sy.simpleegg.platform.BackstagePlatform
import com.sy.simpleegg.room.dao.CashPackageDao
import com.sy.simpleegg.room.entity.CashPackageEntity
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class CashPackageRepository(private val cashPackageDao: CashPackageDao) {

    suspend fun getAllGoods(): MutableList<CashPackageEntity>? {
        return withContext(Dispatchers.IO) {
            cashPackageDao.getAll()
        }
    }

    suspend fun getCashPackageCount(platform: BackstagePlatform): Long {
        return withContext(Dispatchers.IO) {
            cashPackageDao.getCashPackageCount(platform)
        }
    }

    suspend fun getCashPackageData(platform: BackstagePlatform): MutableList<CashPackageEntity>? {
        return withContext(Dispatchers.IO) {
            cashPackageDao.getCashPackageData(platform)
        }
    }

//    suspend fun getLastGoods(platform: BackstagePlatform): MutableList<CashPackageEntity>? {
//        return withContext(Dispatchers.IO) {
//            cashPackageDao.getLastGoods(platform)
//        }
//    }

//    suspend fun insert(CashPackageEntity: CashPackageEntity) {
//        withContext(Dispatchers.IO) {
//            cashPackageDao.insert(CashPackageEntity)
//        }
//    }

    suspend fun insertAll(cashPackageEntity: MutableList<CashPackageEntity>) {
        withContext(Dispatchers.IO) {
            cashPackageDao.insertAll(cashPackageEntity)
        }
    }

    suspend fun delete(cashPackageEntity: CashPackageEntity) {
        withContext(Dispatchers.IO) {
            cashPackageDao.delete(cashPackageEntity)
        }
    }

    suspend fun deleteAll() {
        withContext(Dispatchers.IO) {
            cashPackageDao.deleteAll()
        }
    }
}